﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SetChildRange : MonoBehaviour
{

    public float range;

    public void Set(float range)
    {
        this.range = range;

        int childCount = this.transform.childCount;
        float angle = 360f / (float)childCount;
        var forward = this.transform.forward;
        var pos = this.transform.position;

        for (int i = 0; i < this.transform.childCount; ++i)
        {
            var child = this.transform.GetChild(i);

            child.position = pos + Quaternion.Euler(0, angle * i, 0) * forward * range;
        }
    }

    void OnEnable()
    {
        Set(this.range);
    }

    // Update is called once per frame
#if UNITY_EDITOR
    void Update()
    {
        Set(this.range);
    }
#endif
}
